package cn.zyy.hotel.service.impl;

import cn.zyy.hotel.dao.RoomTypeMapper;
import cn.zyy.hotel.entity.RoomType;
import cn.zyy.hotel.service.RoomTypeService;
import cn.zyy.hotel.vo.RoomTypeVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class RoomTypeServiceImpl implements RoomTypeService {

    @Resource
    private RoomTypeMapper roomTypeMapper;

    //查询房型列表
    public List<RoomType> selectRoomTypeList(RoomTypeVO roomTypeVo) {
        return roomTypeMapper.selectRoomTypeList(roomTypeVo);
    }

    //添加房型
    public int addRoomType(RoomType roomType) {
        //可用房间数默认是全部的房间数量
        roomType.setAvilableNum(roomType.getRoomNum());
        //已预订房间数量
        roomType.setReservedNum(0);
        //已入住房间数量
        roomType.setLivedNum(0);
        return roomTypeMapper.addRoomType(roomType);
    }

    //修改房型
    public int updateRoomType(RoomType roomType) {
        //可用房间数默认是全部的房间数量
        roomType.setAvilableNum(roomType.getRoomNum());
        //已入住的房间数量
        roomType.setLivedNum(0);
        return roomTypeMapper.updateRoomType(roomType);
    }

    //查询当前房型下是否存在房间
    public int getRoomCountByRoomTypeId(Integer roomTypeId) {
        return roomTypeMapper.getRoomCountByRoomTypeId(roomTypeId);
    }

    //删除房型
    public int deleteById(Integer id) {
        return roomTypeMapper.deleteById(id);
    }


}
